const express = require('express');
const router = express.Router();
const GoodModel = require('../models/goods');




router.get('/',function(req,res){
	if(req.session.user){
		var author = req.session.user.name;	
	GoodModel.find().count(function(err,count){
		if(err){
		return	res.json({error: 1,message: '出错'});
		}
			
		GoodModel.find({author}).exec(function(err,datas){
			
			if(err){
			return	res.json({error: 1,message: '出错'});
			}
			res.render('index',{
			title:'商品首页',
			user:req.session.user,
			datas,
			})
			
		})
	})
	}else{
		res.render('log',{
			title:'商品首页'	
		})
		
	}
})



module.exports = router;
